import multiprocessing
import tkinter as tk
from tkinter import ttk
import time
import configparser
import os
import glob
from tkinter import messagebox
from spcparser import *
import shutil
import sys
from web import *

class MainForm(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.master.title("YRI-V设备GOLDEN SAMPLE软件")
        self.pack()
        # 关联关闭事件
        self.master.protocol("WM_DELETE_WINDOW", self.on_closing)
        
        self.notebook = ttk.Notebook(self)
        self.notebook.pack(fill=tk.BOTH, expand=True)
        
        self.tab1 = ttk.Frame(self.notebook)
        self.notebook.add(self.tab1, text='主页/Main')
        
        self.tab2 = ttk.Frame(self.notebook)
        self.notebook.add(self.tab2, text='研判信息/Analyze data')
        
        self.tab3 = ttk.Frame(self.notebook)
        self.notebook.add(self.tab3, text='设置/Setting')

        # region tab1
        self.groupRight = tk.LabelFrame(self.tab1, text="右侧/Right")
        self.text_box = tk.Text(self.groupRight, height=15, width=50, wrap=tk.WORD)
        self.scroll_bar = tk.Scrollbar(self.groupRight, command=self.text_box.yview)
        self.scroll_bar.grid(row=0, column=1, sticky='nsew')
        self.text_box.grid(row=0, column=0, sticky='nsew')
        
        self.groupRight.grid(row=0, column=1, rowspan=2, padx=10, pady=10,sticky='nsew')
        # endregion

        # region tab2
        self.group2 = tk.LabelFrame(self.tab2, text="样本信息/Sample Info")
        
        self.labelExample = tk.Label(self.group2, text="样本信息/example info:")
        self.comboboxExample = ttk.Combobox(self.group2, width=20, values=["aa",'bb','cc'])
        self.btnGetInfo = tk.Button(self.group2, text="获取样本信息/get example info", command=self.getExampleInfo)
        

        

        self.labelExample.grid(row=1, column=0, padx=10, pady=10)
        self.comboboxExample.grid(row=1, column=1, padx=10, pady=10,sticky='nsew')
        self.btnGetInfo.grid(row=1, column=2, padx=10, pady=10)
        
        self.labelError = tk.Label(self.group2, text="总误判数/total error:")
        self.labelError.grid(row=2, column=0, padx=10, pady=10)
        self.entryError = tk.Entry(self.group2, width=20)
        self.entryError.grid(row=2, column=1, padx=10, pady=10,sticky='ew')
        self.btnError = tk.Button(self.group2, text="保存样本信息/save example info", command=None)
        self.btnError.grid(row=2, column=2, padx=10, pady=10, sticky='ew')
        
        self.textBoxExampleDetail = tk.Text(self.group2, height=15, width=50, wrap=tk.WORD)
        self.textBoxExampleDetail.grid(row=3, column=0, columnspan=3, padx=10, pady=10,sticky='nsew')
        self.textBoxExampleDetail_scroll_bar = tk.Scrollbar(self.group2, command=self.textBoxExampleDetail.yview)
        self.textBoxExampleDetail_scroll_bar.grid(row=3, column=3, sticky='nsew')
        self.textBoxExampleDetail.config(yscrollcommand=self.textBoxExampleDetail_scroll_bar.set)
        
        self.group2.grid(row=3, column=0, padx=10, pady=10)
        # endregion
        
        
        # region tab3
        self.group1 = tk.LabelFrame(self.tab3, text="换班/Change Shift")
        
        self.labelShift = tk.Label(self.group1, text="换班时间/Change Shift:")
        self.entryShift = tk.Entry(self.group1, width=24)
        self.btnShiftAdd = tk.Button(self.group1, text="增加换班时间/add shift time",  command=self.changeShiftAdd)
        self.listboxShift = tk.Listbox(self.group1,  height=3)
        self.btnShiftRemove = tk.Button(self.group1, text="删除选中时间/del selected", command=self.changeShiftRemove)
        
        self.labelShift.grid(row=0, column=0, padx=10, pady=10)
        self.entryShift.grid(row=0, column=1, padx=10, pady=10,sticky='ew')
        self.btnShiftAdd.grid(row=0, column=2, padx=10, pady=10,sticky='ew')
        self.listboxShift.grid(row=1, column=0, padx=10, pady=10, columnspan=2,sticky='nsew')
        self.btnShiftRemove.grid(row=1, column=2, padx=10, pady=10,sticky='ew')
        self.group1.grid(row=0, column=0, padx=10, pady=10,sticky='ew')
        
        self.groupIp = tk.LabelFrame(self.tab3, text="样本信息/Sample Info")
        
        self.labelIp = tk.Label(self.groupIp, text="IP地址/IP:")
        self.entryIp = tk.Entry(self.groupIp, width=20)
        self.btnSave = tk.Button(self.groupIp, text="保存IP/save IP", command=None)
        self.labelIp.grid(row=0, column=0, padx=10, pady=10)
        self.entryIp.grid(row=0, column=1, padx=10, pady=10,sticky='ew')
        self.btnSave.grid(row=0, column=2, padx=10, pady=10, sticky='ew')   #, columnspan=2
        
        self.groupIp.grid(row=1, column=0, padx=10, pady=10)
                
        
        
        self.groupLogPath = tk.LabelFrame(self.tab3, text="日志路径/Log Path")
        
        self.labelLogPath = tk.Label(self.groupLogPath, text="日志路径/Log Path:")
        self.entryLogPath = tk.Entry(self.groupLogPath, width=20)
        self.btnLogPath = tk.Button(self.groupLogPath, text="选择日志路径/select log path", command=self.chooseLogPath)
        self.labelLogPath.grid(row=0, column=0, padx=10, pady=10)
        self.entryLogPath.grid(row=0, column=1, padx=10, pady=10,sticky='ew')
        self.btnLogPath.grid(row=0, column=2, padx=10, pady=10, sticky='ew')
        
        self.groupLogPath.grid(row=3, column=0, padx=10, pady=10)
        # endregion

        
    def checkIPValidate(self):
        # 验证IP地址是否合法
        ip = self.entryIp.get()
        if ip == "":
            return False
        if not ip.isdigit():
            return False
        if int(ip) < 0 or int(ip) > 255:
            return False
        return True
    def checkTimeValidate(self):
        # 验证换班时间是否合法
        shift = self.entryShift.get()
        if shift == "":
            return False
        if not shift.isdigit():
            return False
        if int(shift) < 0 or int(shift) > 24:
            return False
        return True
    def changeShiftAdd(self):
        # 添加换班时间
        shift = self.entryShift.get()
        if shift == "":
            return
        if self.listboxShift.size() >= 3:
            messagebox.showwarning("提示", "换班时间最多只能添加三个！")
            return
            
        self.listboxShift.insert(tk.END, shift)
        self.entryShift.delete(0, tk.END)
        
    def changeShiftRemove(self):
        # 删除换班时间
        self.listboxShift.delete(tk.ANCHOR)
            
    def chooseLogPath(self):
        pass
    
    def on_closing(self):
        # 关闭窗口前的事件处理
        self.master.destroy()

    def getExampleInfo(self):
        self.textBoxExampleDetail.delete(1.0, tk.END)
        self.textBoxExampleDetail.insert(tk.END, "这是我从网络获取到的数据..")
if __name__ == "__main__":
        
    # 这里是你的多进程代码
    app = MainForm(master=tk.Tk())
        # 绑定窗口关闭事件
    app.mainloop()